package com.lkd.job;

//自动补货任务生成JOB


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lkd.common.VMSystem;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.service.VendingMachineService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.codehaus.groovy.classgen.ReturnAdder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class SupplyJob {
    @Autowired
    private VendingMachineService vmService;

    @XxlJob("supplyJobHandler")
    public ReturnT<String> supplyJobHandler(String  param){
        LambdaQueryWrapper<VendingMachineEntity> qw = new LambdaQueryWrapper<>();
        qw.eq(VendingMachineEntity::getVmStatus, VMSystem.VM_STATUS_RUNNING);
        List<VendingMachineEntity> vmList = vmService.list(qw);
        vmList.forEach(vm->{
            XxlJobLogger.log("扫描售货机"+vm.getInnerCode());
            vmService.sendSupplyTask(vm.getInnerCode());
        });

        return   ReturnT.SUCCESS;
    }
}
